package auction



import grails.test.mixin.*
import org.junit.*

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestFor(Listing)
class ListingTests {

    void testNoName() {
        String listingStartBid = "20.00"
        Date listingEndDate = new Date().next()
        String listingDescription = "this is a very good hammer"

        Listing listing = new Listing(endDate: listingEndDate, startingBid: listingStartBid)

        assert !listing.validate() : "Listing with no name valid."
    }

    void testNoStartingBid() {
        String listingName = "hammer"
        Date listingEndDate = new Date().next()

        Listing listing = new Listing(name: listingName, endDate: listingEndDate)

        assert !listing.validate() : "Listing with no starting bid valid."
    }

    void testNoEndDate() {
        String listingStartBid = "20.00"
        String listingName = "hammer"

        Listing listing = new Listing(name: listingName, startingBid: listingStartBid)

        assert !listing.validate() : "Listing with no end date valid."
    }

    void testDescriptionMoreThan256()
    {
        String listingStartBid = "20.00"
        String listingName = "hammer"
        Date listingEndDate = new Date().next()
        String listingDescription = "this is a very good hammer." +
        "this is a very good hammer." +
        "this is a very good hammer." +
        "this is a very good hammer." +
        "this is a very good hammer." +
        "this is a very good hammer." +
        "this is a very good hammer." +
        "this is a very good hammer." +
        "this is a very good hammer." +
        "this is a very good hammer." +
        "this is a very good hammer."

        Listing listing = new Listing(name: listingName, startingBid: listingStartBid, endDate: listingEndDate, description: listingDescription)

        assert !listing.validate() : "Listing with no name valid."
    }

    void testFutureDate()
    {
        String listingStartBid = "20.00"
        String listingName = "hammer"
        Date listingEndDate = new Date()

        Listing listing = new Listing(name: listingName, startingBid: listingStartBid, endDate: listingEndDate)

        assert !listing.validate() : "Listing with end date in past valid."
    }

    void testNameGreaterThan64Chars()
    {
        String listingStartBid = "20.00"
        String listingName = "i 10 chars" + "i 10 chars" + "i 10 chars" + "i 10 chars" +
            "i 10 chars" + "i 10 chars" + "i 10 chars"
        Date listingEndDate = new Date().next()

        Listing listing = new Listing(name: listingName, startingBid: listingStartBid, endDate: listingEndDate)

        assert !listing.validate() : "Listing with over 64 chars valid."
    }
}
